<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>薪资发放</title>
<script type="text/javascript" src="../static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jedate.min.js"></script>
<script type="text/javascript"
	src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="../static/easyui/themes/icon.css">
<link rel="stylesheet"
	href="../static/easyui/themes/metro-orange/easyui.css">
<link rel="stylesheet"
	href="../static/easyui/themes/metro-red/window.css">

<link rel="stylesheet"
	href="../static/ttt/css/Salarypayment.css?<%=Math.random()%>">
<script type="text/javascript"
	src="../static/ttt/js/Salarypayment.js?<%=Math.random()%>"></script>

<style type="text/css">
#payment_yuangongmingxi{
	list-style:none;
}
.tes{
	width:30px;
	height:20px;
}
.tess{
	height:20px;
	 
}
</style>
</head>
<body>
	<script type="text/javascript">
		$(function() {
			var empid = "";
			tables();
			//点击新增按钮，弹出window框
			$("#addPayment").click(function() {
				$("#Payment_queding").text("提交")
				//$("#Payment_shenpi").attr("readonly","readonly");
				$("#pament_taozhang").combobox("reload")
				$("#Payment_shenpi").combobox("reload")
				$("#SocialSecurity_s").combobox("reload")
				$("#pament_taozhang").combobox('clear');
				$("#Payment_shenpi").combobox('clear');
				$("#SocialSecurity_s").combobox('clear');
				$("#pament_taozhang").combobox({readonly: false}); 
				$("#SocialSecurity_s").combobox({readonly: false}); 
				$("#Payment_shenpi").combobox({readonly: false}); 
				$("#addPayment_win_text").val("");
				$("#addPayment_win_text").removeAttr("readonly");
				$("#addPaymentt_win_fafangpeploetext").val("");
				$("#addPaymentt_win_fafangpeploetext").removeAttr("readonly");
				$("#addPaymentt_win_win_beizhutext").val("");
				$("#addPaymentt_win_win_beizhutext").removeAttr("readonly");
				$("#addPayments_win").window("open");
			})
			//点击取消，关闭窗户
			$("#Payment_quxiao").click(function() {
				$("#addPayments_win").window("close");
			})

			//点击发放人员，显示改套帐下面所有员工
			$("#addPaymentt_win_fafangpeploetext").click(function() {
				$('#addpaymentyuangong').window("open");
				var setId = $('#pament_taozhang').combobox('getValue');
				$.ajax({
					type : "post",
					url : 'Payment_setid', //数据源地址
					data : {
						setId : setId
					},
					success : function(data) {
						$('#payment_yuangong').datagrid({
							//获取选中的层次
							url : 'payment_yuangong', //数据源地址
							columns : [ [ {
								field : 'EMPID',
								width : 50,
								title : '多选',
								checkbox : true,
								align : "center"
							}, {
								field : 'EMPNAME',
								width : 135,
								title : '员工姓名',
								align : "center"
							} ] ]
						});
					}
				})

			})

			//点击确定，关闭显示员工的窗口
			$("#payment_queding").click(
					function() {
						var checkedItems = $('#payment_yuangong').datagrid(
								'getChecked');
						var names = [];
						empid = "";
						$.each(checkedItems, function(index, item) {
							names.push(item.EMPNAME);
							empid += item.EMPID + ","
						})
						$("#addPaymentt_win_fafangpeploetext").val(names.join(","))
						$('#addpaymentyuangong').window("close");
					})
			//点击确定，新增薪资单
			$("#Payment_queding").click(function() {
				if($("#Payment_queding").text()=="提交"){
					//发放主题
					var slszt = $("#addPayment_win_text").val();
					//薪资套帐
					var perSlySets = $('#pament_taozhang').combobox('getValue')
				
					//社保套帐
					var perSlySzs=$('#SocialSecurity_s').combobox('getValue');
			
					//审批人
					var perPmsEmp2= $('#Payment_shenpi').combobox('getValue');
					
					//套帐人员
					//alert("套帐人员"+empid)
					//备注
					var slsrem=$("#addPaymentt_win_win_beizhutext").val();
					
					var myDate = new Date();
					var data=myDate.getFullYear()+"-"+ (myDate.getMonth());
					//alert(data)
				    var rowsy=$("#Paymenttable").datagrid('getRows');
					var slsname1=$('#pament_taozhang').combobox('getText')
				  	var num=0;
					var setname="";
					for(var i=0;i<rowsy.length;i++){
						var d = new Date(rowsy[i].SLSTIME);
						var times = d.getFullYear() + '-'+ (d.getMonth() + 1)
							//	alert("日期："+data+"----"+times)
							//	alert("套账名称："+rowsy[i].SETNAME+"----"+slsname1)
						if(data==times&&rowsy[i].SETNAME==slsname1){
							setname=rowsy[i].SETNAME;
							num=1;
							break;
						}
					}
					if(num==1){
						alert("本月已发放/创建（审核通过）"+setname+"工资单,请选择其他套账，创建新的薪资单。")
						num=0;
					}else if($("#addPayment_win_text").val()==""){
						$.messager.show({
							title:'信息提示',
							msg: '请输入发放主题',
							timeout:1500,  //1秒后消失
							showType:'slide',//弹出的方式。类似ppt里的图片弹出方式
							//弹出框的样式。居中显示
							style:{
								
							}
						});
					}else if($("#addPaymentt_win_fafangpeploetext").val()==""){
						alert("请选择发放人员")
					}else if(perSlySzs==""){
						alert("请选择社保")
					}else if(perPmsEmp2==""){
						alert("请选择审批人")
					}else if(perSlySets==""){
						alert("请选择薪资套账")
					}else{
						$.ajax({
							type : "post",
							url : 'Payment_sl', //数据源地址
							data : {
								slszt:slszt,
								perSlySets:perSlySets,
								perSlySzs:perSlySzs,
								empid:empid,
								slsrem:slsrem,
								perPmsEmp2:perPmsEmp2
							},
							success : function(data){
								tables();
							}
						})
						$("#addPayments_win").window("close");
					}
				}else if($("#Payment_queding").text()=="确定"){
					$("#addPayments_win").window("close");
				}
			})
			//查询
			$("#selectPayment ").click(function(){
				var text=$(".AccountName").val();
				if(text!=""){
					$('#Paymenttable').datagrid({
						url : 'Paymenttable_ById', //数据源地址
						queryParams: {  		
							text:text  		
						},
						columns : [[
							{field : 'SLSZT',width : 10,title : '发放主题',align : 'center'},
							{field : 'SETNAME',width : 10,title : '套账名称',align : 'center'},
						//	{field : 'SZNAME',width : 10,title : '社保名称',align : 'center'},
							{field : 'EMPNAME',width : 10,title : '创建人',align : 'center'},
							{field : 'EMPNAMES',width : 10,title : '审批人',align : 'center'},
							{field : 'SLSTIME',width : 10,title : '发放月份',align : 'center',
									formatter : function(value) {
										var d = new Date(value);
										var times = d.getFullYear() + '-'
												+ (d.getMonth() + 1)
												
										return times;
									}
							}, 
							{field : 'SLSSTAT',width : 10,title : '状态',
							 	formatter : function(value){
					        		if(value==0){
					        			return "<span style='color:blue;'>未送审</span>";
					        		}else if(value==1){
					        			return "<span style='color:red;'>送审中</span>";
					        		}else if(value==2){
					        			return "<span style='color:rgb(77,216,123);'>已审核</span>";
					        		}else if(value==3){
					        			return "<span style='color:black;'>已发放</span>";
					        		}else if(value==-1){
					        			return "<span style='color:gray;'>未启用</span>";
					        		}
							 	}
							,align : 'center'},
							{field : 'SLSREM',width : 10,title : '备注',align : 'center'},
							{field : 'caozuo',width : 10,formatter : operate_formatter,title : '操作',align : 'center'}]],

						pagination : true,
						pageNumber : 1,
						pageSize : 5,
						pageList : [ 5, 10, 15 ]
					})
				}else if(text==""){
					$.messager.show({
						title:'信息提示',
						msg: '请输入关键字！',
						timeout:1500,  //1秒后消失
						showType:'slide',//弹出的方式。类似ppt里的图片弹出方式
						//弹出框的样式。居中显示
						style:{
							
						}
					});
				}
			})
			//查询全部
			$("#selectPaymentAll").click(function(){
				$(".AccountName").val("");
				tables();
			});
		});
		
		//在每个操作列里面添加编辑，查看，明细，删除
		function operate_formatter(value, row, index) {
			if(row["SLSSTAT"]==0){
				return "<span class='spanclass' onclick='pay_chakan()'>查看</span>/<span class='spanclass' onclick='pay_mingxi()'>明细</span>/<span class='spanclass' onclick='fafang_songshen()'>送审</span>/<span class='spanclass' onclick='pay_jinyong("+row["SLSID"]+")'>禁用</span>";
			}else if(row["SLSSTAT"]==1||row["SLSSTAT"]==3){
				return "<span class='spanclass' onclick='pay_chakan()'>查看</span>/\
				<span class='spanclass' onclick='pay_mingxi()'>明细</span>";
			}else if(row["SLSSTAT"]==2){
				return "<span class='spanclass' onclick='pay_chakan()'>查看</span>/\
				<span class='spanclass' onclick='pay_mingxi()'>明细</span>/\
			    <span onclick='fasong()'style='color:red;' class='spanclass'>发放</span>";
			}
		}
		//禁用
		function pay_jinyong(value){
			$.ajax({	
				type:"post",
				url:'pay_jinyong', //数据源地址
				data : {
					slsid:value
				},
				success: function(datas){ 
					tables();
				}
				
			})
		}
		//发放
		function fasong(){
			var rows=$('#Paymenttable').datagrid("getChecked");
			$.ajax({	
				type:"post",
				url:'Account_fafang', //数据源地址
				data : {
					slsid:rows[0].SLSID
				},
				success: function(datas){ 
					tables();
				}
				
			})
		}
		//送审
		function fafang_songshen(){
			var rows=$('#Paymenttable').datagrid("getChecked");
			$.ajax({	
				type:"post",
				url:'Account_fafang_songshen', //数据源地址
				data : {
					slsid:rows[0].SLSID
				},
				success:function(datas){ 
					tables();
				}
				
			})
		}
		//查看
		function pay_chakan(){
			$("#Payment_queding").text("确定")
			var rows=$('#Paymenttable').datagrid("getChecked");
			$("#pament_taozhang").combobox({readonly: true}); 
			$("#pament_taozhang").combobox('setValue',rows[0].SETNAME);
			$("#Payment_shenpi").combobox({readonly: true}); 
			$("#Payment_shenpi").combobox('setValue',rows[0].EMPNAMES);
			$("#addPayment_win_text").val(rows[0].SLSZT);
			$("#addPayment_win_text").attr("readonly","readonly");
			$("#addPaymentt_win_win_beizhutext").val(rows[0].SLSREM); 
			$("#addPaymentt_win_win_beizhutext").attr("readonly","readonly");
			$.ajax({
				type : "post",
				url : 'pay_chakan', //数据源地址
				data : {
					id:rows[0].SLSID
				},
				success:function(data) {
					//alert(data)
					$("#addPaymentt_win_fafangpeploetext").val(data);
					$("#addPaymentt_win_fafangpeploetext").attr("readonly","readonly");
				}
			})
				$.ajax({
				type : "post",
				url : 'pay_chakanshebao', //数据源地址
				data : {
					slsid:rows[0].SLSID
				},
				success:function(data) {
					$("#SocialSecurity_s").combobox({readonly: true}); 
					$("#SocialSecurity_s").combobox('setValue',data);
					
				}
				
			})
			$("#addPayments_win").window("open");
		}
		function tables(){
			$('#Paymenttable').datagrid({
				url : 'Paymenttable', //数据源地址
				columns : [[
					{field : 'SLSID',width : 10,title : '编号',hidden:true,align : 'center'},
					{field : 'SLSZT',width : 10,title : '发放主题',align : 'center'},
					{field : 'SETNAME',width : 10,title : '套账名称',align : 'center'},
					{field : 'EMPNAME',width : 10,title : '创建人',align : 'center'},
					{field : 'EMPNAMES',width : 10,title : '审批人',align : 'center'},
					{field : 'SLSTIME',width : 10,title : '发放月份',align : 'center',
							formatter : function(value) {
								var d = new Date(value);
								var times = d.getFullYear() + '-'
										+ (d.getMonth() + 1)
								return times;
							}
						}, 
						{field : 'SLSSTAT',width : 10,title : '状态',
						 	formatter : function(value){
				        		if(value==0){
				        			return "<span style='color:blue;'>未送审</span>";
				        		}else if(value==1){
				        			return "<span style='color:red;'>送审中</span>";
				        		}else if(value==2){
				        			return "<span style='color:rgb(77,216,123);'>已审核</span>";
				        		}else if(value==3){
				        			return "<span style='color:black;'>已发放</span>";
				        		}
				        	}	
						,align : 'center'},
						{field : 'SLSREM',width : 10,title : '备注',align : 'center'},
						{field : 'caozuo',width : 10,formatter : operate_formatter,title : '操作',align : 'center'}]],

				pagination : true,
				pageNumber : 10,
				pageSize : 5,
				pageList : [ 5, 10, 15 ]
			})
		}
		function pay_mingxi(){
			
			var rows=$('#Paymenttable').datagrid("getChecked");
			$.ajax({
				type : "post",
				url : 'pay_yuagongmingxi', //数据源地址
				data : {
					id:rows[0].SLSID
				},
				success:function(data) {
					 console.log(data)
					 var tb = document.getElementById('payment_yuangongmingxi');
				     var rowNum=tb.rows.length;
				     for (i=0;i<rowNum;i++) {
				         tb.deleteRow(i);
				         rowNum=rowNum-1;
				         i=i-1;
				     } 
						var str=$("<tr class='tes' style='border-bottom:1px solid;'></tr>");
					 	var str1="";
					 	var str2="";
					 	var str3="";
					 	var str4="";
					 	console.log(data)
						for (var key in data[0]) {
		      				//alert(key); 
		      				 if(key=="员工姓名"){
		      					str1=$( "<th style='width:120px;height:25px;line-height:25px;text-align:center;'>"+key+"</th>");
		      				 }else if(key=="应发工资"){
		      					str3 += "<th style='width:120px;height:25px;line-height:25px;text-align:center;'>"+key+"</th>";
		      				 }else if(key=="实发工资"){
		      					str4 += "<th style='width:120px;height:25px;line-height:25px;text-align:center;'>"+key+"</th>";
		      				 }else if(key!="员工姓名"||key!="应发工资"||key!="实发工资"){
		      					 str2 += "<th style='width:120px;height:25px;line-height:25px;text-align:center;'>"+key+"</th>";
		      				 }
						}
						
						
						$("#payment_yuangongmingxi").append(str);
						str.append(str1);
						str.append(str2);
						str.append(str3);
						str.append(str4);
						var str="";
					 	var str1="";
					 	var str2="";
					 	var str3="";
					 	var str4="";
						var tr="";
						var tr1="";
						var tr2="";
						var tr3="";
						var tr4="";
						for(var i=0;i<data.length;i++){
							 tr +="<tr class='tess' style='border-bottom:1px solid;'>";
							 	for (var value in data[i]) {
							 		if(value=="员工姓名"){
								 		tr1+="<td style='width:120px;height:25px;line-height:25px;text-align:center;'>"+data[i][value]+"</td>";
				      					
							 		}else if(value=="应发工资"){
							 			tr3+="<td style='width:120px;height:25px;line-height:25px;text-align:center;'>"+data[i][value]+"</td>";
				      					
				      				 }else if(value=="实发工资"){
							 			tr4+="<td style='width:120px;height:25px;line-height:25px;text-align:center;'>"+data[i][value]+"</td>";
				      					
				      				 }else if(value!="员工姓名"||value!="应发工资"||value!="实发工资"){
									 	tr2+="<td style='width:120px;height:25px;line-height:25px;text-align:center;'>"+data[i][value]+"</td>";
				      						
				      				 }
								}
							 	tr+=tr1+tr2+tr3+tr4+"</tr>";
							 	$("#payment_yuangongmingxi").append(tr);
							 	tr="";
							 	tr1="";
							 	tr2="";
							 	tr3="";
							 	tr4="";
						       
						}
				 $("#addPayments_mingxi").window("open")
				}
			})
		}
	</script>
		<div id="addPayments_mingxi" class="easyui-window" title="薪资发放明细"
		style="width: 950PX; height: 600px"
		data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
			<table id="payment_yuangongmingxi"style="width: 1100px;overflow-y:scroll;margin:5px;">
			</table>
		</div>
	<div id="addPayments_win" class="easyui-window" title="薪资发放"
		style="width: 720px; height: 480px"
		data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
		<div id="addpaymentyuangong" class="easyui-window" title="员工表格信息"
			style="width: 190px; padding-top: 5px; height: 500px"
			data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
			<table id="payment_yuangong" class="easyui-datagrid"
				style="width:175px;; height: 380px">
			</table>
			<button id="payment_queding" style="margin-top: 15px;margin-left: 52px;">确定</button>
		</div>
		<div id="addPayment_win_box" class="addPayment_win_box">
			<a id="addPayment_win_name" class="addPayment_win_Account" style="">发放主题：</a>
			<input id="addPayment_win_text" class="addPayment_win_text"
				type="text" />
		</div>
		<div id="addPayment_win_box2" class="addPayment_win_box">
			<a id="addPayment_win_Account" class="addPayment_win_Account" style="">选择套账：</a> 
			<input id="pament_taozhang" class="easyui-combobox"
			data-options="valueField:'SETID',textField:'SETNAME',url:'pament_shenpiren'">
	<%-- 		<select id="AccountSelect">
				<c:forEach items="${payment_}" var="p">
					<option id="${p.SETID}">${p.SETNAME}</option>
				</c:forEach>
			</select> --%>
		</div>
		<div id="addPayment_win_box3" class="addPayment_win_box">
			<a id="addPayment_win_people" class="addPayment_win_Account" style="">审批人：</a>
<!-- 			<input id="Payment_shenpi" style="width: 174px;"
				class="addPayment_win_text" type="text" /> -->
					<input id="Payment_shenpi" class="easyui-combobox"
					data-options="valueField:'EMPID',textField:'EMPNAME',url:'payment_shenmpi'">
		<%-- 	 	<select id="Payment_shenpi" style="width:174px;height:25px;">
								<c:forEach items="${payment_shenmpi}" var="p">
									<option id="${p.EMPID}">${p.EMPNAME}</option>
								</c:forEach>
						</select> --%>

		</div>
		<div id="addPayment_win_box4" class="addPayment_win_box">
			<a id="addPayment_win_Accountyear" class="addPayment_win_Account"
				style="">社保：</a> 
				<input id="SocialSecurity_s" class="easyui-combobox"
					data-options="valueField:'SZID',textField:'SZNAME',url:'SocialSecurity_s'">
			<%-- 	<select id="SocialSecurity">
					<c:forEach items="${sz_}" var="s">
						<option id="${s.szid }">${s.szname}</option>
					</c:forEach>
				</select> --%>
		</div>
		<div id="addPayment_win_box5" class="addPayment_win_box">
			<a id="addPayment_win_fafangpeploe" class="addPayment_win_Account"
				style="">发放人员：</a>
			<textarea cols="50" rows="10" id="addPaymentt_win_fafangpeploetext"
				class="addPayment_win_fafangpeploetext" type="text"></textarea>
			<!-- 	<a id="ched">选择人员</a> -->
		</div>
		<div id="addPayment_win_box6" class="addPayment_win_box">
			<a id="addPayment_win_beizhu" class="addPayment_win_Account" style="">备注：</a>
			<textarea cols="50" rows="10" id="addPaymentt_win_win_beizhutext"
				class="addPayment_win_fafangpeploetext" type="text"></textarea>
			<!-- <a id="ched2">选择人员</a>  -->
		</div>
		<hr id="PaymentHr">
		<div class="addPayment_win_box7">
			<button id="Payment_queding" style="margin-right: 15px;">
			<img src="../static/tyl/images/go.png">
			提交</button>
			<button id="Payment_quxiao">
			<img src="../static/tyl/images/cha.png">
			取消</button>
		</div>
	</div>
	<div class="head_1">
		<span class="fontstyle">名称：</span><input text="text"
			class="AccountName">
		<!--  	<span class="fontstyle">状态：</span>
				 	<select id="states">
				 			<option>审核中</option>
				 			<option>送审中</option>
				 			<option>已通过</option>
				 	</select> -->
		<button id="selectPayment" style="margin-right: 15px;">查询</button>
		<button id="selectPaymentAll" style="margin-right: 15px;">查询全部</button>
		<button id="addPayment">新增</button>
	</div>
	<div class="table_1">
		<table id="Paymenttable" class="easyui-datagrid"
			style="width: 100%; height: 470px;" data-options=" fitColumns:true">
		</table>
	</div>
</body>
</html>